package ctrl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import service.Impl.IOrderStateServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/*
* @description: 当用户点击退款按钮时的业务。更改订单状态
*/
public class OrderReturn extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
//        resp.setContentType("text/html,charset=utf-8");

//        ServletInputStream inputStream=req.getInputStream();
//        BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(inputStream));
//        StringBuilder builder=new StringBuilder();
//        String temp="";
//        while((temp=bufferedReader.readLine())!=null){
//            builder.append(temp);
//        }
//        String jsonString=builder.toString();
//        JSONObject jsonObject=JSON.parseObject(jsonString);
//        int orderId=Integer.parseInt(jsonObject.getString("orderId"));
        int orderId=Integer.parseInt(req.getParameter("orderId"));
        //测试
//        int orderId=Integer.parseInt(req.getParameter("orderId"));

        //具体业务逻辑
        //更改订单状态
        IOrderStateServiceImpl orderStateService=new IOrderStateServiceImpl();
        String orderState="退货中";
        orderStateService.updateOrderStateByOrderId(orderId,orderState);

        //跳转展示订单界面
        resp.sendRedirect("/showOrder");

    }
}
